package weiyi.security.config.Component;

import cn.hutool.json.JSONUtil;
import com.weiyi.common.common.api.CommonResult;
import com.weiyi.common.common.api.ResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import java.io.IOException;

public class AccessDeniedHandlerResult implements AccessDeniedHandler {
    @Override
    public void handle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(JSONUtil.parse(CommonResult.failed(ResultCode.FORBIDDEN)));
        response.getWriter().flush();
    }
}
